package com.novel.base.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * LayUIPage
 *
 * @author 樊温军
 * @date 2025/4/8 下午3:40
 */
@Data
@AllArgsConstructor
public class LayUIPage<T> {
    private int code;
    private String msg;
    private Long count;
    private List<T> data;

    /**
     * 只有总条数和分页数据的构造方法
     *
     * @param count 总条数
     * @param data  分页数据
     */
    public LayUIPage(Long count, List<T> data) {
        this.count = count;
        this.data = data;
    }

    public static <T> LayUIPage<T> ok(IPage<T> iPage, String msg) {
        return new LayUIPage<>(R.SUCCESS_CODE, msg, iPage.getTotal(), iPage.getRecords());
    }

    public static <T> LayUIPage<T> failed(String msg) {
        return new LayUIPage<>(R.FAILURE_CODE, msg, 0L, new ArrayList<T>());
    }

}
